﻿using CardMonitor.Model;
using CardMonitor.Utils;
using CardMonitor.Windows;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DotNetSpeech;
using System.Windows.Threading;
using Spire.Pdf;
using System.Net;
using System.IO;
using CardMonitor.ViewModel;

namespace CardMonitor.Pages
{
    /// <summary>
    /// Card.xaml 的交互逻辑
    /// </summary>
    public partial class ReplacementCard : Page
    {
        BillModel billModel = null;
        private PortControlHelper pchSend;
        private PortControlHelper portWrite;
        private String curInputTag = "mobile";
        private SolidColorBrush activeBrush = new SolidColorBrush(Color.FromRgb(186, 234, 255));
        MainWindow mainWindow = null;
        SynchronizationContext _syncContext = null;
        ImageBrush imageBrush;
        SpVoice speech = new SpVoice();
        IndexViewModel viewModel;
        System.Drawing.Image image;
        IntPtr icdev = IntPtr.Zero;

        InputWindow carInputWindow = null;
        KeyBoardWindow inputWindow = null;
        private Action<int, String> callbackAction;

        int st;
        public ReplacementCard()
        {
            InitializeComponent();
            billModel = new BillModel();
            viewModel = new IndexViewModel();
            viewModel.index = 0;
            _syncContext = SynchronizationContext.Current;



            this.DataContext = billModel;
            mainWindow = (MainWindow)Window.GetWindow(this);

            this.Loaded += MMPage_Loaded;//该事件在控件完成布局、渲染并准备好交互时触发

            callbackAction += CallBackExcute;

        }
        public void MMPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.KeyDown += MMPage_KeyDown;
            if (!"销售业务".Equals(billModel.Type))
            {
                billModel.OuterSkinWeight = "";
                billModel.OuterGrossWeight = "";
                //txtWaiPi.Visibility = Visibility.Visible;
                // wpBorder.Visibility = Visibility.Visible;
                //txtWaiMao.Visibility = Visibility.Visible;
                //wmBorder.Visibility = Visibility.Visible;
            }
            //读取IC卡

        }

        private void TextBox_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            string index = (string)((System.Windows.Controls.TextBlock)sender).Tag;
            int v = int.Parse(index);

            _syncContext.Post(showInputWindow, v);

        }

        private void showInputWindow(object obj)
        {
            int index = (int)obj;
            viewModel.index = index;
            if (index == 1 || index == 2)
            {
                if (carInputWindow != null)
                {
                    carInputWindow.Hide();
                }

                if (inputWindow == null)
                {
                    inputWindow = new KeyBoardWindow(callbackAction);
                    inputWindow.Owner = mainWindow;
                    inputWindow.Width = mainWindow.Width;
                    inputWindow.Left = mainWindow.Left;
                    inputWindow.Top = SystemParameters.PrimaryScreenHeight - inputWindow.Height;
                }
                inputWindow.maxLength = 7;
                inputWindow.getFlag("2");

                if (index == 2)
                {
                    inputWindow.viewModel.carNoArray.Clear();
                    foreach (String v in viewModel.waiPiWeighArray)
                    {
                        if (v != "")
                        {
                            inputWindow.viewModel.carNoArray.Add(v);
                        }

                    }
                }
                else if (index == 1)
                {
                    inputWindow.viewModel.carNoArray.Clear();
                    foreach (String v in viewModel.waiMaoWeighArray)
                    {
                        if (v != "")
                        {
                            inputWindow.viewModel.carNoArray.Add(v);
                        }

                    }
                }
                inputWindow.showKeys(3);
                inputWindow.Show();
            }
            else if (index == 3)
            {
                if (inputWindow != null)
                {
                    inputWindow.Hide();
                }
                if (carInputWindow == null)
                {
                    carInputWindow = new InputWindow(callbackAction);
                    carInputWindow.Owner = mainWindow;
                    carInputWindow.Width = mainWindow.Width;
                    carInputWindow.Left = mainWindow.Left;
                    carInputWindow.Top = SystemParameters.PrimaryScreenHeight - carInputWindow.Height;
                }
                carInputWindow.maxLength = 7;
                carInputWindow.viewModel.carNoArray.Clear();
                foreach (String v in viewModel.carNoArray02)
                {
                    if (v != "")
                    {
                        carInputWindow.viewModel.carNoArray.Add(v);
                    }

                }

                if (carInputWindow.viewModel.carNoArray.Count == 0)
                {
                    carInputWindow.showKeys(1);
                }
                else
                {
                    carInputWindow.showKeys(2);
                }
                carInputWindow.Show();
            }
            else
            {
                if (inputWindow != null && inputWindow.IsActive)
                {
                    inputWindow.Hide();
                }
                if (carInputWindow != null && carInputWindow.IsActive)
                {
                    carInputWindow.Hide();
                }
            }
        }


        private void CallBackExcute(int index, string val)
        {
            if (viewModel.index == 3)
            {
                viewModel.carNoArray02[index] = val;
                //BillModel.PiNumberList.Add(val);
                //BillModel.PiNumberList[index] = val;
                billModel.TrailerNumber = String.Join("", viewModel.carNoArray02);
            }

            if (viewModel.index == 1)
            {
                viewModel.waiMaoWeighArray[index] = val;
                //BillModel.PiNumberList.Add(val);
                //BillModel.PiNumberList[index] = val;
                string inputStr = String.Join("", viewModel.waiMaoWeighArray);
                billModel.OuterGrossWeight = inputStr;

            }

            if (viewModel.index == 2)
            {
                viewModel.waiPiWeighArray[index] = val;
                //BillModel.PiNumberList.Add(val);
                //BillModel.PiNumberList[index] = val;
                string inputStr = String.Join("", viewModel.waiPiWeighArray);
                billModel.OuterSkinWeight = inputStr;

            }
        }

        public ReplacementCard(BillModel billModel, MainWindow _win)
        {
            InitializeComponent();
            _syncContext = SynchronizationContext.Current;

            this.billModel = billModel;
            viewModel = new IndexViewModel();
            viewModel.index = 0;
            this.Loaded += new RoutedEventHandler(Sign_Loaded);

            this.DataContext = billModel;
            mainWindow = _win;
            this.Loaded += MMPage_Loaded;
            callbackAction += CallBackExcute;
            /*
                        if (billModel.TrailerNumber != null)
                        {
                            char[] charArray = billModel.TrailerNumber.ToCharArray();
                            for (int i = 0; i < billModel.TrailerNumber.Length; i++)
                            {
                                viewModel.carNoArray02.Add(charArray[i].ToString());
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 7; i++)
                            {
                                viewModel.carNoArray02.Add("");
                            }
                        }*/

            if (billModel.TrailerNumber != null)
            {
                char[] charArray = billModel.TrailerNumber.ToCharArray();

                int len = billModel.TrailerNumber.Length;


                if (len < 7)
                {
                    for (int i = 0; i < billModel.TrailerNumber.Length; i++)
                    {
                        viewModel.carNoArray02.Add(charArray[i].ToString());
                    }

                    for (int i = 0; i < 7 - len; i++)
                    {
                        viewModel.carNoArray02.Add("");
                    }

                }
                else
                {
                    for (int i = 0; i < 7; i++)
                    {
                        viewModel.carNoArray02.Add(charArray[i].ToString());
                    }
                }

            }
            else
            {
                for (int i = 0; i < 7; i++)
                {
                    viewModel.carNoArray02.Add("");
                }
            }
        }
        public void setPersonImage(ImageBrush image)
        {
            this.imageBrush = image;
            // this.cardImagePanel.Background = image;//身份证照片

            //System.Drawing.Image bmp = image; // 自己初始化的有效的 image
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
            //bi.BeginInit();
            //bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
            //bi.EndInit();
            //cardImage.Source = bi; // done!
            //ms.Close();

            //System.Drawing.Image bmp = image; // 自己初始化的有效的 image
            //System.Windows.Media.Imaging.BitmapSource bi =
            //System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
            //bmp.GetHbitmap(),
            //IntPtr.Zero,
            //Int32Rect.Empty,
            //BitmapSizeOptions.FromEmptyOptions());
            // 上面以 bmp 格式为例的,其他格式自处理
            //this.cardImage.Source = bi; // Done!
            //this.image = image;
            //this.cardImage.Source= BitmapFrame.Create(image, BitmapCreateOptions.None, BitmapCacheOption.Default);;
        }
        private void Sign_Loaded(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(cardInfo.CardNo);
            //System.IO.MemoryStream objMSPhoto = new System.IO.MemoryStream(cardInfo.ArrPhotoByte, 0, cardInfo.ArrPhotoByte.Length);

            //ImageBrush imageBrush = new ImageBrush();
            //ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
            //imageBrush.ImageSource = (ImageSource)imageSourceConverter.ConvertFrom(objMSPhoto);

            //this.cardImagePanel.Background = imageBrush;

            //MessageBox.Show(billModel.CarNo);
        }
        private void goIndex(object sender, RoutedEventArgs e)
        {
            Index index = new Index(mainWindow);
            mainWindow.BreakSpeak();
            CardDeviceUtil.ReceiveCard();
            NavigationService.GetNavigationService(this).Navigate(index);

            //NavigationService.GetNavigationService(this).Navigate(new Uri("/Pages/Index.xaml", UriKind.Relative));
        }

        private void showMessage(String message)
        {
            InfoWindow infoWindow = new InfoWindow(message);
            infoWindow.Owner = mainWindow;
            infoWindow.ShowDialog();
        }
        private Nullable<double> getZhong(String type)
        {
            try
            {
                if ("waiPi".Equals(type))
                {
                    return 0.0;// billModel.OuterSkinWeight;
                }
                else if ("waiMao".Equals(type))
                {
                    return 0.0;// billModel.OuterGrossWeight;
                }
                else
                {
                    return 0.0;
                }
            }
            catch
            {
                return 0.0;
            }
        }
        private void doMakeCard(object sender, RoutedEventArgs e)
        {
            string WorkMode = (string)App.getConfig().WorkMode;
            if (WorkMode.Equals("0"))
            {
                doMakeCardIC();//IC卡
            }
            else
            {
                doMakeCardID();//身份证
            }
        }
        private void doMakeCardID()
        {

            mainWindow.BreakSpeak();
            String ifstatement = App.getConfig().IfStatement;
            if (ifstatement.Equals("0"))
            {
                bool flag = click_statement();
                if (!flag)
                {
                    NavigationService.GetNavigationService(this).GoBack();
                    return;
                }
            }
            String url = "http://" + App.getConfig().HttpServerIp + ":" + App.getConfig().HttpServerPort + "/guns/sysFileInfo/upload2";
            JObject json = new JObject();
            json.Add("id", billModel.Id);
            // json.Add("facId", billModel.DriverCard);
            json.Add("facId", billModel.driverMacCard);
            json.Add("trailerNumber", billModel.TrailerNumber);
            json.Add("carNumber", billModel.CarNumber);
            HttpPostWindow httpPostWindow1 = new HttpPostWindow();
            httpPostWindow1.Owner = mainWindow;
            httpPostWindow1.setParamObject(json);
            string warning = httpPostWindow1.getWarning();
            httpPostWindow1.setOperation(HttpPostWindow.OperationType.uploadMakeCardResult.ToString());
            bool result1 = (bool)httpPostWindow1.ShowDialog();
            if (!result1)
            {
                string message = httpPostWindow1.getMessage();
                if (null == message || "".Equals(message))
                {
                    message = "车辆报到失败,请联系工作人员处理";
                }
                if (null != warning && "" != warning)
                {
                    mainWindow.Speak(warning);
                    showMessage(warning);
                    Thread.Sleep(1000);
                }
                mainWindow.Speak(message);
                showMessage(message);
                //CardDeviceUtil.ReceiveCard();
                Index index1 = new Index(mainWindow);

                NavigationService.GetNavigationService(this).Navigate(index1);
                return;
            }

            showMessage("车辆报到完成");


            Index index = new Index(mainWindow);

            NavigationService.GetNavigationService(this).Navigate(index);

        }
        private void doMakeCardIC()//IC卡
        {

            mainWindow.BreakSpeak();

            String ifstatement = App.getConfig().IfStatement;
            if (ifstatement.Equals("0"))
            {
                bool flag = click_statement();
                if (!flag)
                {
                    NavigationService.GetNavigationService(this).GoBack();
                    return;
                }
            }
            //写卡
            String uuid = CardUtil.getCardGUID();
            billModel.Juid = uuid;
            MakeCardWindow makeCardWindow = new MakeCardWindow();//写卡
            makeCardWindow.setModel(billModel);
            makeCardWindow.Owner = mainWindow;// 建立窗口层级关系
            bool result = (bool)makeCardWindow.ShowDialog();//显示窗口
            if (result)
            {
                JObject json = new JObject();
                json.Add("guidCode", billModel.DriverCard);//司机身份证号
                int checkResult = this.checkCard(json);//对比数据
                if (checkResult != 1)
                {
                    showMessage("写卡校验失败,请重新点击制卡");
                    NavigationService.GetNavigationService(this).GoBack();
                    CardDeviceUtil.ReceiveCard();//回收卡
                    return;
                }
                String url = "http://" + App.getConfig().HttpServerIp + ":" + App.getConfig().HttpServerPort + "/guns/sysFileInfo/upload2";
                //JObject json = new JObject();
                JObject json2 = new JObject();
                json2.Add("id", billModel.Id);
                json2.Add("facId", billModel.DriverCard);
                json2.Add("trailerNumber", billModel.TrailerNumber);
                json2.Add("carNumber", billModel.CarNumber);
                HttpPostWindow httpPostWindow1 = new HttpPostWindow();
                httpPostWindow1.Owner = mainWindow;
                httpPostWindow1.setParamObject(json2);
                string warning = httpPostWindow1.getWarning();
                httpPostWindow1.setOperation(HttpPostWindow.OperationType.uploadMakeCardResult.ToString());
                bool result1 = (bool)httpPostWindow1.ShowDialog();
                if (!result1)
                {
                    string message = httpPostWindow1.getMessage();
                    if (null == message || "".Equals(message))
                    {
                        message = "车辆报到失败,请联系工作人员处理";
                    }
                    if (null != warning && "" != warning)
                    {
                        mainWindow.Speak(warning);
                        showMessage(warning);
                        Thread.Sleep(1000);
                    }
                    mainWindow.Speak(message);
                    showMessage(message);
                    CardDeviceUtil.ReceiveCard();//回收卡
                    Index index1 = new Index(mainWindow);

                    NavigationService.GetNavigationService(this).Navigate(index1);
                    return;
                }

                showMessage("车辆报到完成");
                MakeCardSucces();//吐卡
                Index index = new Index(mainWindow);
                NavigationService.GetNavigationService(this).Navigate(index);

            }
        }

        private int checkCard(JObject paramObj)
        {
            ReadCardWindow readcardWindow = new ReadCardWindow();

            bool result = (bool)readcardWindow.ShowDialog();
            if (!result)
            {
                return -1;
            }
            String guidCode = paramObj["guidCode"].ToString();
            if (!guidCode.Equals(readcardWindow.billModel.DriverCard))
            {
                return -2;
            }

            return 1;
        }

        private void MakeCardSucces()
        {
            showMessage("制卡成功,请取卡");
            CardDeviceUtil.PopupCard();
            //  Reader.hc_exit(icdev);


        }
        private void MakeCardError()
        {
            showMessage("制卡失败,请联系管理员");
        }


        private void doInput(object sender, RoutedEventArgs e)
        {
            String val = ((Button)sender).Content.ToString();

            inputText(val);
        }
        private void inputText(String val)
        {
            //    String value = "";
            //    if (curInputTag == "wp")
            //    {
            //        value = this.wpText.Text;
            //    }
            //    else if (curInputTag == "wm")
            //    {
            //        value = this.wmText.Text;
            //    }
            //    else if (curInputTag == "mobile")
            //    {
            //        value = this.mobileText.Text;
            //    }

            //    String value2 = "";
            //    if ("-1".Equals(val))
            //    {
            //        if (value.Length > 0)
            //        {
            //            value2 = value.Substring(0, value.Length-1);
            //        }
            //    }
            //    else
            //    {
            //        value2 = getNumField(value, val);
            //    }

            //    if (curInputTag == "wp")
            //    {
            //        this.wpText.Text = value2;
            //    }
            //    else if (curInputTag == "wm")
            //    {
            //        this.wmText.Text = value2;
            //    }
            //    else if (curInputTag == "mobile")
            //    {
            //        this.mobileText.Text = value2;
            //    }
        }
        private String getNumField(String val, String inputVal)
        {
            if (inputVal == "消除")
            {
                return "";
            }
            if (inputVal == "." && curInputTag == "mobile")
            {
                return val;
            }
            if (inputVal == "." && "".Equals(val))
            {
                return val;
            }
            if (inputVal == "." && val.IndexOf(".") >= 0)
            {
                return val;
            }

            if (curInputTag == "mobile" && val.Length >= 11)
            {
                return val;
            }

            if ((curInputTag == "wp" || curInputTag == "wm") && val.IndexOf(".") >= 0)
            {
                if (val.IndexOf(".") + 3 == val.Length) return val;
            }
            if ((curInputTag == "wp" || curInputTag == "wm") && !"".Equals(val))
            {
                if (double.Parse(val + inputVal) > 99.99) return val;
            }

            String value = val;

            value = val + inputVal;

            return value;
        }

        public void MMPage_KeyDown(object sender, KeyEventArgs e)
        {
            string val = getKeyValue(e.Key);
            if ("back".Equals(val))
            {
                inputText("-1");
            }
            else if ("point".Equals(val))
            {
                inputText(".");
            }
            else
            {
                if (e.Key.ToString().StartsWith("D"))
                {
                    inputText(val);
                }
            }
            //MessageBox.Show(e.Key.ToString());
            e.Handled = true;
        }

        private string getKeyValue(Key key)
        {
            string KeyValue = "-1";

            switch (key)
            {
                case Key.D1:
                    KeyValue = "1";
                    break;
                case Key.D2:
                    KeyValue = "2";
                    break;
                case Key.D3:
                    KeyValue = "3";
                    break;
                case Key.D4:
                    KeyValue = "4";
                    break;
                case Key.D5:
                    KeyValue = "5";
                    break;
                case Key.D6:
                    KeyValue = "6";
                    break;
                case Key.D7:
                    KeyValue = "7";
                    break;
                case Key.D8:
                    KeyValue = "8";
                    break;
                case Key.D9:
                    KeyValue = "9";
                    break;
                case Key.D0:
                    KeyValue = "0";
                    break;
                case Key.OemPeriod:
                    KeyValue = "point";
                    break;
                case Key.Back:
                    KeyValue = "back";
                    break;
                case Key.Enter:
                    KeyValue = "enter";
                    break;
            }
            return KeyValue;
        }
        private bool click_statement()
        {
            StatementWindow statementWindow = new StatementWindow();
            statementWindow.setPersonImage(this.imageBrush);
            statementWindow.setBillModel(this.billModel);
            Grid layer = new Grid() { Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(200, 0, 0, 0)) };
            UIElement original = mainWindow.Content as UIElement;//MainWindows父窗体
            mainWindow.Content = null;
            //容器Grid
            Grid container = new Grid();
            container.Children.Add(original);//放入原来的内容
            container.Children.Add(layer);//在上面放一层蒙板
            //将装有原来内容和蒙板的容器赋给父级窗体
            mainWindow.Content = container;
            statementWindow.Owner = mainWindow;
            bool result = (bool)statementWindow.ShowDialog();
            return result;
        }

        public void UploadImage(string uploadUrl, string imgPath, long id, string fileparameter = "file")
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(uploadUrl) as HttpWebRequest;
                request.AllowAutoRedirect = true;
                request.Method = "POST";
                request.ServicePoint.Expect100Continue = false;

                string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
                request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
                byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
                byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");

                int pos = imgPath.LastIndexOf("/");
                string fileName = imgPath.Substring(pos + 1);

                //请求头部信息
                StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"" + fileparameter + "\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
                byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());

                FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
                byte[] bArr = new byte[fs.Length];
                fs.Read(bArr, 0, bArr.Length);
                fs.Close();

                Stream postStream = request.GetRequestStream();
                postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
                postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                postStream.Write(bArr, 0, bArr.Length);
                postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
                postStream.Close();

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                Stream instream = response.GetResponseStream();
                StreamReader sr = new StreamReader(instream, Encoding.UTF8);
                string content = sr.ReadToEnd();
                JObject rspJson = JObject.Parse(content);
                string code = rspJson["code"].ToString();
                if (code.Equals("00000"))
                {
                    JObject data = (JObject)rspJson.GetValue("data");
                    String filaName = (String)data.GetValue("fileObjectName");
                    doUpdateScreenPicture(filaName, id);
                }
            }
            catch (Exception ex) { }

        }
        private void doUpdateScreenPicture(String imagePath, long id)
        {
            JObject paramObject = new JObject();
            paramObject.Add("imagePath", imagePath);
            paramObject.Add("id", id);

            try
            {
                String serverIp = App.getConfig().HttpServerIp;
                String serverPort = App.getConfig().HttpServerPort;
                String response = HttpPostHelper.doHttpPost("http://" + serverIp + ":" + serverPort + "/qd-s-factory/clientApi/updateBillCardPicture", paramObject.ToString());
                JObject rspJson = JObject.Parse(response);

            }
            catch (Exception ex) { }
        }

        private void returnn(object sender, RoutedEventArgs e)//返回
        {
            this.NavigationService.GoBack();
        }

        private void ReplaceCard(object sender, RoutedEventArgs e)
        {
            NewCardInfo newCardInfo = null;
            int code = NewIDcardread.CardAuthentication();//身份认证
            if (code == 1)
            {

                newCardInfo = NewIDcardread.ReadIDcard();
                if (newCardInfo == null)
                {
                    showMessage("未读取到身份证信息");
                }
                else
                {
                    goMakeCard(newCardInfo.driverMacCard);
                }
            }
            else
            {

                showMessage("请重新放置身份证");

            }
        }
        public void goMakeCard(String driverMacCard)
        {
            JObject json = new JObject();
            json.Add("id", billModel.Id);
            json.Add("facId", driverMacCard);
            HttpPostWindow httpPostWindow1 = new HttpPostWindow();
            httpPostWindow1.Owner = mainWindow;
            httpPostWindow1.setParamObject(json);
            string warning = httpPostWindow1.getWarning();
            httpPostWindow1.setOperation(HttpPostWindow.OperationType.uploadMacIdCode.ToString());
            bool result1 = (bool)httpPostWindow1.ShowDialog();
            if (!result1)
            {
                string message = httpPostWindow1.getMessage();
                if (null == message || "".Equals(message))
                {
                    message = "补卡失败,请联系工作人员处理";
                }

                mainWindow.Speak(message);
                showMessage(message);
                //CardDeviceUtil.ReceiveCard();
                Index index1 = new Index(mainWindow);

                NavigationService.GetNavigationService(this).Navigate(index1);
                return;
            }

            showMessage("补卡完成");


            Index index = new Index(mainWindow);

            NavigationService.GetNavigationService(this).Navigate(index);
        }
    }
}
